#ifndef __GNSS_H
#define __GNSS_H 

#include "main.h"
#define PIe                      3.1415926
#define EARTH_RADIUS            6378.137
//GPS NMEA-0183 
//
__packed typedef struct  
{										    
 	uint8_t num;		//
	uint8_t eledeg;	//
	uint16_t azideg;	//
	uint8_t sn;		//		   
}nmea_satellitemsg; 
// NMEA-0183 
//
__packed typedef struct  
{	
 	uint8_t beidou_num;		//
	uint8_t beidou_eledeg;	//
	uint16_t beidou_azideg;	//
	uint8_t beidou_sn;		//		   
}beidou_nmea_satellitemsg; 

//UTC
__packed typedef struct  
{										    
 	uint16_t year;	//
	uint8_t month;	//
	uint8_t date;	//
	uint8_t hour; 	//
	uint8_t min; 	//
	uint8_t sec; 	//
}nmea_utc_time;   	   
//NMEA 0183 
__packed typedef struct  
{										    
 	uint8_t svnum;					//GPS
	uint8_t beidou_svnum;			//GPS
	nmea_satellitemsg slmsg[12];		//12GPS
	beidou_nmea_satellitemsg beidou_slmsg[12];		//12
	nmea_utc_time utc;			//UTC
	uint32_t latitude;				// 100000,100000
	uint8_t nshemi;					///,N:;S:				  
	uint32_t longitude;			    // 100000,100000
	uint8_t ewhemi;					///,E:;W:
	uint8_t gpssta;					//GPS:0,;1,;2,;6,.				  
 	uint8_t posslnum;				//GPS,0~12.
 	uint8_t possl[12];				//
	uint8_t fixmode;					//:1,;2,2D;3,3D
	uint16_t pdop;					// 0~500,0~50.0
	uint16_t hdop;					// 0~500,0~50.0
	uint16_t vdop;					// 0~500,0~50.0 

	int altitude;			 	//,10,10.:0.1m	 
	uint16_t speed;					//,1000,10.:0.001/	 
}nmea_msg;
 
int NMEA_Str2num(uint8_t *buf,uint8_t*dx);
void NMEA_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_GPGSV_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_BDGSV_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_GNGGA_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_GNGSA_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_GNGSA_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_GNRMC_Analysis(nmea_msg *gpsx,uint8_t *buf);
void NMEA_GNVTG_Analysis(nmea_msg *gpsx,uint8_t *buf);
void utc_to_local(nmea_utc_time* time);
float get_distance(double lat1, double lng1, double lat2, double lng2);
#endif

